package pers.lipeng.snake;

import javax.swing.*;
import java.awt.*;

/**
 * @author APengG
 */
public class Food extends JLabel {
    private int bodyX;
    private int bodyY;
    public Food(int x,int y){
        this.bodyX = x;
        this.bodyY = y;
        this.setSize(new Dimension(15,15));
        ImageIcon imageIcon = new ImageIcon(getClass().getResource("/snake/img/food.png"));
        Image image = imageIcon.getImage();
        Image scaledInstance = image.getScaledInstance(15, 15, Image.SCALE_DEFAULT);
        imageIcon.setImage(scaledInstance);
        this.setIcon(imageIcon);
    }

    public Food loadBounds(int x,int y){
        this.bodyX = x;
        this.bodyY = y;
        return this;
    }

    public void loadIcon(){
        int width = this.getWidth();
        int height = this.getHeight();
        ImageIcon imageIcon = new ImageIcon(getClass().getResource("/snake/img/food.png"));
        Image image = imageIcon.getImage().getScaledInstance(width,height,Image.SCALE_DEFAULT);
        imageIcon.setImage(image);
        this.setIcon(imageIcon);
    }

}
